package com.mzj.saas.mservice.announcement.controller;

import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.announcement.service.AnnouncementService;
import com.mzj.saas.mservice.announcement.vo.AnnouncementVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * 公告管理
 */
@Controller
@RequestMapping("/announcement")
public class AnnouncementController {
    @Autowired
    private AnnouncementService announcementService;

    /*
     *公告详情显示
     */
    @PostMapping(value = "advertDetailShow")
    @ResponseBody
    public ResultBean<Object> advertDetailShow(@RequestHeader String accessToken,
                                               @RequestParam(name = "id", required = false) Long id) {
        return announcementService.advertDetailShow(accessToken, id);
    }

    /*
     *公告删除
     */
    @PostMapping(value = "deleteAdvert")
    @ResponseBody
    public ResultBean<Object> deleteAdvert(@RequestHeader String accessToken,
                                           @RequestParam(name = "id", required = false) Long id) {
        return announcementService.deleteAdvert(accessToken, id);
    }

    /**
     * 公告发布
     *
     * @param vo
     * @param file
     * @return
     */
    @PostMapping(value = "publishAdvert")
    @ResponseBody
    public ResultBean<Object> publishAdvert(@RequestHeader String accessToken, AnnouncementVO vo,
                                            @RequestParam(value = "file", required = false) MultipartFile file) {
        return announcementService.save(accessToken, vo, file);
    }

    /**
     * 富文本
     * 广告详情上传图片
     *
     * @param file
     * @return
     */
    @PostMapping(value = "upload")
    @ResponseBody
    public Map<String, Object> uploadDetailFile(@RequestParam(value = "file", required = false) MultipartFile file) {
        return announcementService.uploadDetailFile(file);
    }
    /**
     * 富文本
     * 广告详情上传图片
     *
     * @param file
     * @return
     */
    @PostMapping(value = "upload1")
    @ResponseBody
    public Map<String, Object> uploadDetailFile1(@RequestBody MultipartFile file) {
        return announcementService.uploadDetailFile(file);
    }

    /**
     * 富文本图片删除
     *
     * @param paths
     */
    @PostMapping(value = "upload/del")
    @ResponseBody
    public void deleteDetailFile(String paths) {
        announcementService.deleteDetailFile(paths);
    }

    /*
     *获取社区列表
     */
    @PostMapping(value = "getCommunityList")
    @ResponseBody
    public ResultBean<Object> getCommunityList(@RequestHeader String accessToken) {
        return announcementService.getCommunityList(accessToken);
    }

    /*
     *获取小区列表
     */
    @PostMapping(value = "getVillageList")
    @ResponseBody
    public ResultBean<Object> getVillageList(@RequestHeader String accessToken) {
        return announcementService.getVillageList(accessToken);
    }

}
